package com.exercises;


import com.exercises.common.TreeNode;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

class Exercise872 {
    List<Integer> list1 = new ArrayList<>();
    List<Integer> list2 = new ArrayList<>();

    public boolean leafSimilar(TreeNode root1, TreeNode root2) {
        dfs(root1, list1);
        System.out.println(list1);
        dfs(root2, list2);
        System.out.println(list2);
        return list1.equals(list2);
    }

    public void dfs(TreeNode treeNode, List<Integer> str) {
        if (treeNode == null) return;
        if (treeNode.left == null && treeNode.right == null) {
            str.add(treeNode.val);
        } else {
            dfs(treeNode.left, str);
            dfs(treeNode.right, str);
        }

    }
}

